home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / demo.pro < prev    next >
Text File  |  1997-07-08  |  41KB  |  1,256 lines

  1. ;$Id: demo.pro,v 1.65 1997/04/28 21:10:45 alan Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       demo.pro
  9. ;
  10. ;  CALLING SEQUENCE: demo
  11. ;
  12. ;  PURPOSE:
  13. ;       Main demo shell.
  14. ;
  15. ;  MAJOR TOPICS: All topics in IDL 5.0.
  16. ;
  17. ;  CATEGORY:
  18. ;       IDL 5.0
  19. ;
  20. ;  INTERNAL FUNCTIONS and PROCEDURES:
  21. ;
  22. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  23. ;       pro gettips           -  Read the tip file
  24. ;       pro widtips           -  Create the tip widgets
  25. ;       pro sizetips          -  Size the tip widgets
  26. ;
  27. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  28. ;
  29. ;  NAMED STRUCTURES:
  30. ;       none.
  31. ;
  32. ;  COMMON BLOCS:
  33. ;       none.
  34. ;
  35. ;  MODIFICATION HISTORY:
  36. ;       3/97,    ACY   - Modified
  37. ;-
  38. ;----------------------------------------------------------------------------
  39. ;
  40. ;  Purpose:  Display a message.
  41. ;
  42. function temp_msg, $
  43.     string        ; IN: message string
  44.  
  45.     message = ["Not yet implemented..."," ", $
  46.          "When implemented, will go to", "   " + string]
  47.     temp = DIALOG_MESSAGE ( message )
  48. end
  49.  
  50.  
  51. pro timer, text, t0             ;Print times & update current time
  52. t1 = systime(1)
  53. print, text, ' ', t1 - t0
  54. t0 = t1
  55. end
  56.  
  57. pro DoAScreen, Index, lun, hdr, Image, R, G, B
  58. ; Writes an image to the gif file, and saves its color table in the
  59. ; header structure.  We assume that images may have a maximum of 128
  60. ; colors. 
  61.  
  62. m = max(image)
  63. if m gt 127 then begin
  64.     print, 'Image ', index,' is out of range, reducing'
  65.     reduce_colors, Image, v
  66.     if n_elements(v) lt 128 then v = [v, bytarr(128 - n_elements(v))]
  67.     r = r(v)
  68.     g = g(v)
  69.     b = b(v)
  70. endif
  71.  
  72. point_lun, -lun, position       ;Get & save current position
  73. hdr[index].start = position
  74. hdr[index].dims = (size(image))(1:2)
  75. for j=0, (n_elements(r) < 128)-1 do begin
  76.     hdr[index].colortb[j] = r[j]
  77.     hdr[index].colortb[j+128] = g[j]
  78.     hdr[index].colortb[j+256] = b[j]
  79. endfor
  80. ENCODE_GIF, lun, Image
  81. print, index, position, m
  82. end
  83.  
  84.  
  85.  
  86. ;----------------------------------------------------------------------------
  87. ;
  88. ;  Purpose:  Create the gif file from the .sav file
  89. ;
  90. pro WriteDemoscreen
  91.  
  92. t0 = systime(1)
  93. restore, filepath('screens.sav', SUBDIR=['examples','demo','demodata'])
  94. timer, 'ReadImages/restore', t0
  95. lun = 0
  96.  
  97. nimages = long(15)
  98.  
  99. openw, lun, 'screens.gif', /get_lun
  100. header = replicate({ Start: 0L, dims: lonarr(2), $
  101.                      colortb: bytarr(128*3)}, nimages)
  102. writeu, lun, nimages, header
  103.  
  104. DoAScreen, 0,  lun, header, mainScreen, MainR, MainG, MainB
  105. DoAScreen, 1,  lun, header, analysisScreen, analysisR, analysisG, analysisB
  106. DoAScreen, 2,  lun, header, appdevScreen, appdevR,appdevG,appdevB
  107. DoAScreen, 3,  lun, header, callrsiScreen, callrsiR,callrsiG,callrsiB
  108. DoAScreen, 4,  lun, header, earthScreen, earthR,earthG,earthB
  109. DoAScreen, 5,  lun, header, engineerScreen, engineerR,engineerG,engineerB
  110. DoAScreen, 6,  lun, header, medicalScreen, medicalR,medicalG,medicalB
  111. DoAScreen, 7,  lun, header, rsiprodScreen, rsiprodR,rsiprodG,rsiprodB
  112. DoAScreen, 8,  lun, header, spaceScreen, spaceR,spaceG,spaceB
  113. DoAScreen, 9,  lun, header, vizScreen, vizR,vizG,vizB
  114. DoAScreen, 10, lun, header, enviScreen,enviR,enviG,enviB
  115. DoAScreen, 11, lun, header, vhScreen,vhR,vhG,vhB
  116. DoAScreen, 12, lun, header, dataminerScreen,dataminerR,dataminerG,dataminerB
  117. DoAScreen, 13, lun, header, insightScreen,insightR,insightG,insightB
  118.  
  119. ; Save the initial splash scren as the last image...
  120. READ_GIF, filepath("splash.gif", $
  121.                    SUBDIR=['examples','demo','demodata']), $
  122.   splashImg, splashR, splashG, splashB
  123. DoAScreen, 14, lun, header, splashImg, splashR, splashG, splashB
  124.  
  125. point_lun, lun, 0
  126. byteorder, nimages, /HTONL
  127. tmp = header.start
  128. byteorder, tmp, /HTONL
  129. header.start = tmp
  130. writeu, lun, nimages, header
  131. free_lun, lun
  132. end
  133.  
  134. Function OpenDemoscreens, Name, Header
  135. ; Open the Demo screens file and read the header, If OK return 1,
  136. ; otherwise negative error code.
  137.  
  138. openr, lun, name, /GET_LUN, ERROR=i ;Open up the file containing screens
  139. if i lt 0 then begin
  140.     j = DIALOG_MESSAGE(["Can't read the demo screen file", Name], /ERROR)
  141.     return, i
  142. endif
  143.  
  144. nimages = 0L
  145. readu, lun, nimages             ;Read # of images
  146. byteorder, nimages, /NTOHL      ;Correct byteorder
  147.  
  148. tmp = replicate({ Start: 0L, $  ;Read file header
  149.                   dims: lonarr(2), $
  150.                   colortb: bytarr(128,3)$
  151.                 }, nimages)
  152. readu, lun, tmp
  153.  
  154. t = tmp.start                   ;Correct for byte ordering
  155. byteorder, t, /NTOHL
  156. tmp.start = t
  157.  
  158. t = tmp.dims
  159. byteorder, t, /NTOHL
  160. tmp.dims = t
  161.  
  162. header = { lun : lun, $         ;Combine
  163.            count: 0L, $
  164.            start: tmp.start, $
  165.            dims: tmp.dims, $
  166.            colortb: tmp.colortb, $
  167.            cache: ptrarr(nimages), $
  168.            time: lonarr(nimages)}
  169. return, 1
  170. end
  171.  
  172.  
  173. Function PReadDemoScreen, Index, Header, Colortable, NO_CACHE=no_cache, $
  174.                          DEBUG = debug
  175. ; Return a pointer to an image for screen number Index.
  176. ; Return colortable in Colortable
  177.  
  178. Null = ptr_new()
  179. Nkeep = 3                       ;# of images to keep in cache
  180. Header.count = Header.count + 1 ;Keep track of time
  181.  
  182. if Header.cache(Index) ne Null then begin ;Already there?
  183.     Result = Header.cache(Index)
  184. ;    if keyword_set(debug) then print,'cached ', Index
  185. endif else begin
  186.     in = where(header.cache ne Null, count)
  187.     if count ge Nkeep then begin ;Must get rid of an image
  188.         junk = min(header.time(in), Toss);Find image that been in the longest
  189.         toss = in(toss)
  190. ;        if keyword_set(debug) then print, 'Removed ', toss
  191.         ptr_free, Header.cache(toss)
  192.         Header.cache(toss) = Null
  193.     endif
  194.     lun = Header.Lun
  195.     point_lun, lun, Header.start[index] ;Start of image in file
  196.     image = bytarr(Header.dims[0,index], Header.dims[1,index], $ ;Array to Read
  197.                    /NOZERO)
  198.     DECODE_GIF, lun, Image
  199.     result = ptr_new(Image, /NO_COPY)
  200.     if keyword_set(no_cache) eq 0 then Header.cache(Index) = result
  201. ;    if keyword_set(debug) then print, 'Read ', index
  202. endelse
  203.  
  204. Header.time[Index] = Header.count
  205. Colortable = Reform(Header.colortb(*,*,Index))
  206. Return, Result                  ;Return the pointer to the image
  207. end
  208.  
  209.  
  210. ;----------------------------------------------------------------------------
  211. ;
  212. ;  Purpose:  Set up the splash screens.
  213. ;
  214. pro demoSplashStart, $
  215.     fullScrXsize, $   ; IN: X monitor size
  216.     fullScrYsize, $   ; IN: Y monitor size
  217.     splashImage, $    ; IN: Image to display
  218.     splashColors, $   ; IN: Colortable for image
  219.     splashBase, $     ; OUT: Splash base ID
  220.     startSplash       ; OUT: Starting time
  221.  
  222. s = size(splashImage)
  223. nx = s(1)
  224. ny = s(2)
  225. splashXoffset = (fullScrXsize-nx)/2
  226. splashYoffset = (fullScrYsize-ny)/2
  227. splashBase = WIDGET_BASE ( tlb_frame_attr=31, $
  228.                            xoffset=splashXoffset, yoffset=splashYoffset )
  229. splashDraw = widget_draw ( splashBase, xsize=nx, ysize=ny )
  230. WIDGET_CONTROL, splashBase, map=0
  231. WIDGET_CONTROL, splashBase, /realize
  232. TVLCT, SplashColors
  233. WIDGET_CONTROL, splashDraw, GET_VALUE=splashDrawID
  234. WSET, splashDrawID
  235. TV, splashImage
  236. splashImage = 0                 ;Don't need it anymore
  237. WIDGET_CONTROL, splashBase, map=1
  238.  
  239. startSplash = systime ( 1 )
  240. end
  241.  
  242. ;----------------------------------------------------------------------------
  243. ;
  244. ;  Purpose:  End the display of the splash screen
  245. ;
  246. pro demoSplashEnd, $
  247.     startSplash, $   ; IN: Starting time
  248.     splashBase, $    ; IN: Splash base ID
  249.     debug            ; IN: Debug mode 1=on, 0= off
  250.  
  251.     ;  End the display of the splash screen
  252.     ;
  253.     endSplash = systime ( 1 )
  254.     deltaSplash = endSplash - startSplash
  255.     if ( debug eq 1 ) then begin
  256.         print, " Elapsed time for splash screen =====", deltaSplash
  257.     end
  258.     ; while ( deltaSplash le 4.0 ) do begin
  259.         ; print, 'In wait loop ...'
  260.         ; wait, 0.25
  261.         ; deltaSplash = systime ( 1 ) - endSplash
  262.     ; endwhile
  263.     WIDGET_CONTROL, splashBase, /destroy
  264.  
  265.     ;if ( debug eq 1 ) then begin
  266.         ;print, " Total elapsed time for splash screen ", deltaSplash
  267.     ;end
  268.  
  269. end
  270.  
  271. ;----------------------------------------------------------------------------
  272. ;
  273. ;  Purpose:  Reset the system variables.
  274. ;
  275. pro idl_demo_reset
  276.  
  277.     Set_Shading, LIGHT=[0.0, 0.0, 1.0], /REJECT, /GOURAUD, $
  278.         VALUES=[0, (!D.N_Colors-1L)]
  279.  
  280.     T3d, /RESET
  281.     !P.T3d = 0
  282.     !P.Position = [0.0, 0.0, 0.0, 0.0]
  283.     !P.Clip = [0L, 0L, (!D.X_Size-1L), (!D.Y_Size-1L), 0L, 0L]
  284.     !P.Region = [0.0, 0.0, 0.0, 0.0]
  285.     !P.Background = 0L
  286.     !P.Charsize = 8.0 / Float(!D.X_Ch_Size)
  287.     !P.Charthick = 0.0
  288.     !P.Color = !D.N_Colors - 1L
  289.     !P.Font = (-1L)
  290.     !P.Linestyle = 0L
  291.     !P.Multi = [0L, 0L, 0L, 0L, 0L]
  292.     !P.Noclip = 0L
  293.     !P.Noerase = 0L
  294.     !P.Nsum = 0L
  295.     !P.Psym = 0L
  296.     !P.Subtitle = ''
  297.     !P.Symsize = 0.0
  298.     !P.Thick = 0.0
  299.     !P.Title = ''
  300.     !P.Ticklen = 0.02
  301.     !P.Channel = 0
  302.  
  303.     !X.S = [0.0, 1.0]
  304.     !X.Style = 0L
  305.     !X.Range = 0
  306.     !X.Type = 0L
  307.     !X.Ticks = 0L
  308.     !X.Ticklen = 0.0
  309.     !X.Thick = 0.0
  310.     !X.Crange = 0.0
  311.     !X.Omargin = 0.0
  312.     !X.Window = 0.0
  313.     !X.Region = 0.0
  314.     !X.Charsize = 0.0
  315.     !X.Minor = 0L
  316.     !X.Tickv = 0.0
  317.     !X.Tickname = ''
  318.     !X.Gridstyle = 0L
  319.     !X.Tickformat = ''
  320.  
  321.     !Y = !X
  322.     !Z = !X
  323.  
  324.     !X.Margin = [10.0, 3.0]     ;.Margin is different for x,y,z
  325.     !Y.Margin = [4.0, 2.0]
  326.     !Z.Margin = 0
  327. end
  328.  
  329.  
  330. pro button_group, buttons, index, x0, y0, ydelta, screen, Names, DEFINE=ndefine
  331. ; Define a column of buttons.  
  332. ; Inputs: buttons = array of button structures.
  333. ; Index = index of next button to define.  On exit, index is incremented.
  334. ; x0, y0 = starting coordinate for the first button.  y0 is output as
  335. ; the starting coordinate for the next button.
  336. ; ydelta = vertical spacing between buttons.
  337. ; screen = screen index of button.
  338. ; Names = [2,n] array of Button values and uvalues.
  339.  
  340. n = n_elements(names)/2
  341. xsize = 130
  342. ysize = 23
  343.  
  344. for i=0, n-1 do begin
  345.     s = { d5btn_s, $
  346.           Value: Names[i*2], $
  347.           Uvalue: Names[i*2+1], $
  348.           xsize: xsize, $
  349.           ysize: ysize, $
  350.           xoffset: fix(x0), $
  351.           yoffset: fix(y0), $
  352.           screenNum: fix(screen), $
  353.           btnbase: 0L$
  354.     }
  355.     if index eq 0 then $        ;Define array?
  356.       buttons = replicate(s, ndefine)
  357.     
  358.     buttons[index] = s
  359.     y0 = y0 + ydelta
  360.     index = index + 1
  361.  
  362. endfor
  363.  
  364. end
  365.                        
  366. ;----------------------------------------------------------------------------
  367. ;
  368. ;  Purpose:  Define (not create) the push down
  369. ;            buttons within the splash screens.
  370. ;
  371. pro buttonDef, buttons
  372.  
  373. numButtons = 71
  374. index = 0
  375.  
  376.     ;  Main level buttons, screen 0, group 1
  377. ystart = 115
  378. button_group, buttons, index, 36, ystart, 27, 0, DEFINE=numButtons, $
  379.   ['Earth Sciences', '.4', $ ;  Main level buttons, screen 0, group 1
  380.    'Engineering', '.5', $
  381.    'Medical', '.6', $
  382.    'Space/Physics', '.8']
  383.  
  384. button_group, buttons, index, 36, ystart + 27, 27, 0, $
  385.    ['RSI Products', '.7']
  386.  
  387. ;  Main level buttons, screen 0, group 2
  388. ystart = 243
  389. button_group, buttons, index, 485, ystart, 27, 0, $ 
  390.   ['Visualization', '.9', $
  391.    'Data Analysis', '.1', $
  392.    'Application Development', '.2']
  393. button_group, buttons, index, 485, ystart + 27, 27, 0, $ 
  394.    ['Contact RSI', '.3']
  395.  
  396.     ;  Second Level Buttons, screens are listed in alphabetical order,
  397.     ;  not screen order.  Vertical Spacing is 29 pixels.
  398.  
  399.     ;  Analysis Buttons, screen 1
  400. button_group, buttons, index, 75, 40, 29, 1, $
  401.   [ 'Math and Statistics', 'D_MATHSTAT', $
  402.     'Matrix Data', 'D_MATRIX', $
  403.     'Signal Processing', 'FILTER-SIGNAL', $
  404.     'Image Processing', 'D_IMAGPROC', $
  405.     'Venn Diagrams', 'D_VENN', $
  406.     'Wavelets', 'D_WAVELET', $
  407.     'People of RSI', 'D_PEOPLE', $
  408.     'Return to Main Screen', '.0']
  409.  
  410. button_group, buttons, index, 330, 200, 29, 2, $
  411.   [ 'GUI Development', 'D_WIDGETS', $ ;  AppDev Buttons, screen 2
  412.     'Database Connectivity','.12', $
  413.     'Development Environment','?DEVENV', $
  414.     'OO Programming', '?OOPROG', $
  415.     'Cross Platform Dev', '?CROSS', $
  416.     'Return to Main Screen', '.0']
  417.  
  418. button_group, buttons, index, 383, 324, 29, 3, $
  419.   [ 'Return to Main Screen', '.0']
  420.  
  421. button_group, buttons, index, 85, 38, 29, 4, $
  422.   ['Mapping', 'D_MAP', $      ;  Earth Buttons, screen 4
  423.    'Tides', 'D_TIDES', $
  424.    'Globe', 'D_GLOBE', $
  425.    'Texture Mapping', 'D_TEXTURE', $
  426.    'Flyby', 'D_FLYBY', $
  427.    'Environmental Modeling', 'D_TANKLEAK', $
  428.    'ENVI', '.10', $
  429.    'Return to Main Screen', '.0']
  430.  
  431.  
  432. button_group, buttons, index, 66, 57, 29, 5, $
  433.   ['Forecasting', 'D_FORECAST', $    ;  Engineering Buttons, screen 5
  434.    'Optimization', 'D_OPTIMIZE', $
  435.    'Fourier Filtering', 'FILTER-ENGR', $
  436.    'CFD', 'D_CFD', $
  437.    'Time Series', 'D_T_SERIES', $
  438.    'Return to Main Screen', '.0']
  439.  
  440. button_group, buttons, index, 402, 92, 29, 6, $
  441.   ['Reconstruction', 'D_RECONSTR', $ ;  Medical Buttons, screen 6
  442.    'Image Animation', 'D_GATED', $
  443.    'Beating Heart', 'D_HEART', $
  444.    'Volumes', 'D_VOLRENDR', $
  445.    'Visible Human', '.11', $
  446.    'Return to Main Screen', '.0']
  447.  
  448. button_group, buttons, index, 410, 100, 29, 7, $
  449.   ['IDL Insight', '.13', $ ;  RSI Product Buttons, screen 7
  450.    'ENVI', '.10', $
  451.    'Visible Human', '.11', $
  452.    'IDL DataMiner', '.12', $
  453.    'Return to Main Screen', '.0']
  454.  
  455. button_group, buttons, index, 29, 261, 29, 8, $
  456.   ['Fourier Filtering', 'FILTER-SPACE', $ ; Space Buttons, screen 8
  457.    'ROI Segmentation', 'ROI-SPACE', $
  458.    'Return to Main Screen', '.0']
  459.  
  460.  
  461. if !version.os_family NE 'Windows' then begin
  462. button_group, buttons, index, 53, 160, 29, 9, $
  463.   ['2D Plotting', 'D_PLOT2D', $     ;  Viz Buttons, screen 9, group 1
  464.    'Contouring', 'D_CONTOUR', $
  465.    '3D Geometry', 'D_OBJECT3D', $
  466.    'Surface Objects', 'D_SURFVIEW', $
  467.    'Volumes', 'D_VOLRENDR', $
  468.    'US Census', 'D_USCENSUS', $
  469.    'Vibrating Membrane', 'D_VIBMEMBR']
  470. endif else begin
  471. ;;; Don't allow US Census demo if Windows
  472. button_group, buttons, index, 53, 160, 29, 9, $
  473.   ['2D Plotting', 'D_PLOT2D', $     ;  Viz Buttons, screen 9, group 1
  474.    'Contouring', 'D_CONTOUR', $
  475.    '3D Geometry', 'D_OBJECT3D', $
  476.    'Surface Objects', 'D_SURFVIEW', $
  477.    'Volumes', 'D_VOLRENDR', $
  478.    'Vibrating Membrane', 'D_VIBMEMBR']
  479. endelse
  480.  
  481. button_group, buttons, index, 390, 125, 29, 9, $
  482.   ['Mapping', 'D_MAP', $      ;  Viz Buttons, screen 9, group 2
  483.    'Gridding', 'D_GRIDDING', $
  484.    'Texture Mapping', 'D_TEXTURE', $
  485.    'Flyby', 'D_FLYBY', $
  486.    'Orbit', 'D_ORBIT', $
  487.    'Slicer', 'D_SLICE', $
  488.    'Return to Main Screen', '.0']
  489.  
  490. button_group, buttons, index, 20, 375, 29, 10, $ ;  ENVI Buttons, screen 10
  491.   ['Back','.-']
  492.  
  493. button_group, buttons, index, 20, 375, 29, 11, $ ;  VH Buttons, screen 11
  494.   ['Back','.-']
  495.  
  496. button_group, buttons, index, 20, 375, 29, 12, $ ;  DataMiner Buttons, screen 12
  497.   ['Back','.-']
  498.  
  499. button_group, buttons, index, 120, 275, 29, 13, $ ;  Insight Buttons, screen 13
  500.   ['Start IDL Insight','INSIGHT-START']
  501. button_group, buttons, index, 20, 375, 29, 13, $
  502.   ['Back','.-']
  503.  
  504. end
  505.  
  506.  
  507. pro GetMenuDescription, MenuDescription ;Define the menu string arrays.
  508.  
  509. MenuDescription = $
  510.   [   '1\File', '', $
  511.       '2\Quit', 'quit', $
  512.       '1\Applications', '', $
  513.       '1\Earth Sciences', '', $
  514.       '0\Mapping', 'D_MAP', $
  515.       '0\Oceanic Tides Animation', 'D_TIDES', $
  516.       '0\Globe', 'D_GLOBE', $
  517.       '0\Texture Mapped Terrain', 'D_TEXTURE', $
  518.       '0\Terrain Flyby', 'D_FLYBY', $
  519.       '0\Environmental Modeling', 'D_TANKLEAK', $
  520.       '2\ENVI', '.10', $
  521.       '1\Engineering', '', $
  522.       '0\Forecasting', 'D_FORECAST', $
  523.       '0\Optimization', 'D_OPTIMIZE', $
  524.       '0\Fourier Filtering', 'FILTER-ENGR', $
  525.       '0\Computational Fluid Dynamics', 'D_CFD', $
  526.       '2\Time Series', 'D_T_SERIES', $
  527.       '1\Medical', '', $
  528.       '0\Image Reconstruction', 'D_RECONSTR', $
  529.       '0\Image Animation', 'D_GATED', $
  530.       '0\Beating Heart', 'D_HEART', $
  531.       '0\Volume Visualization', 'D_VOLRENDR', $
  532.       '2\Visible Human', '.11' ]
  533.  
  534. if !version.os_family NE 'Windows' then begin
  535. MenuDescription = $            ;Cause strings are too long to concatenate
  536.   [   MenuDescription, $
  537.       '1\Physics and Space Sciences', '', $
  538.       '0\Fourier Filtering', 'FILTER-SPACE', $
  539.       '2\ROI Segmentation', 'ROI-SPACE', $
  540.       '3\RSI Products', '', $
  541.       '0\IDL Insight', '.13', $
  542.       '0\ENVI', '.10', $
  543.       '0\Visible Human CD', '.11', $
  544.       '2\IDL Dataminer', '.12', $
  545.       '1\Features', '', $
  546.       '1\Visualization', '', $
  547.       '0\2D Plotting', 'D_PLOT2D', $
  548.       '0\Contouring', 'D_CONTOUR', $
  549.       '0\3D Geometry Viewing', 'D_OBJECT3D', $
  550.       '0\Surface Objects', 'D_SURFVIEW', $
  551.       '0\Volume Visualization', 'D_VOLRENDR', $
  552.       '0\US Census', 'D_USCENSUS', $
  553.       '0\Vibrating Membrane', 'D_VIBMEMBR', $
  554.       '0\Mapping', 'D_MAP', $
  555.       '0\Gridding and Interpolation', 'D_GRIDDING', $
  556.       '0\Texture Mapped Terrain', 'D_TEXTURE', $
  557.       '0\Terrain Flyby', 'D_FLYBY', $
  558.       '0\Orbiting Satellite', 'D_ORBIT', $
  559.       '2\Slicer', 'D_SLICE', $
  560.       '1\Data Analysis', '', $
  561.       '0\Math and Statistics', 'D_MATHSTAT', $
  562.       '0\Matrix Data', 'D_MATRIX', $
  563.       '0\Signal Processing', 'FILTER-SIGNAL', $
  564.       '0\Image Processing', 'D_IMAGPROC', $
  565.       '0\Venn Diagrams', 'D_VENN', $
  566.       '0\Wavelets', 'D_WAVELET', $
  567.       '2\The People of RSI', 'D_PEOPLE', $
  568.       '3\Application Development', '',$
  569.       '0\GUI Development', 'D_WIDGETS', $
  570.       '0\Database Connectivity', '.12', $
  571.       '0\Development Environment', '?DEVENV', $
  572.       '0\Object Oriented Programming', '?OOPROG', $
  573.       '2\Cross Platform Development', '?CROSS']
  574. endif else begin
  575. ;;; Don't allow US Census demo if Windows
  576. MenuDescription = $            ;Cause strings are too long to concatenate
  577.   [   MenuDescription, $
  578.       '1\Physics and Space Sciences', '', $
  579.       '0\Fourier Filtering', 'FILTER-SPACE', $
  580.       '2\ROI Segmentation', 'ROI-SPACE', $
  581.       '3\RSI Products', '', $
  582.       '0\IDL Insight', '.13', $
  583.       '0\ENVI', '.10', $
  584.       '0\Visible Human CD', '.11', $
  585.       '2\IDL Dataminer', '.12', $
  586.       '1\Features', '', $
  587.       '1\Visualization', '', $
  588.       '0\2D Plotting', 'D_PLOT2D', $
  589.       '0\Contouring', 'D_CONTOUR', $
  590.       '0\3D Geometry Viewing', 'D_OBJECT3D', $
  591.       '0\Surface Objects', 'D_SURFVIEW', $
  592.       '0\Volume Visualization', 'D_VOLRENDR', $
  593.       '0\Vibrating Membrane', 'D_VIBMEMBR', $
  594.       '0\Mapping', 'D_MAP', $
  595.       '0\Gridding and Interpolation', 'D_GRIDDING', $
  596.       '0\Texture Mapped Terrain', 'D_TEXTURE', $
  597.       '0\Terrain Flyby', 'D_FLYBY', $
  598.       '0\Orbiting Satellite', 'D_ORBIT', $
  599.       '2\Slicer', 'D_SLICE', $
  600.       '1\Data Analysis', '', $
  601.       '0\Math and Statistics', 'D_MATHSTAT', $
  602.       '0\Matrix Data', 'D_MATRIX', $
  603.       '0\Signal Processing', 'FILTER-SIGNAL', $
  604.       '0\Image Processing', 'D_IMAGPROC', $
  605.       '0\Venn Diagrams', 'D_VENN', $
  606.       '0\Wavelets', 'D_WAVELET', $
  607.       '2\The People of RSI', 'D_PEOPLE', $
  608.       '3\Application Development', '',$
  609.       '0\GUI Development', 'D_WIDGETS', $
  610.       '0\Database Connectivity', '.12', $
  611.       '0\Development Environment', '?DEVENV', $
  612.       '0\Object Oriented Programming', '?OOPROG', $
  613.       '2\Cross Platform Development', '?CROSS']
  614. endelse
  615.  
  616. MenuDescription = $             ;Cause strings are too long to concatenate
  617.   [   MenuDescription, $
  618.       '1\Help', '', $
  619.       '2\IDL Online Help Navigator', '?NOARG', $
  620.       '1\About', '', $
  621.       '0\About the IDL Demo', '>abt_demo|About this Demo', $
  622.       '1\About Research Systems', '', $
  623.       '0\History of Research Systems', '>abt_rsi|History of Research Systems', $
  624.       '0\Distributors', ">abt_dist|Research Systems' Distributors", $
  625.       '0\The People of RSI', 'D_PEOPLE', $
  626.       '0\Training Courses', '>abt_trng|Research Systems Training', $
  627.       '0\Consulting', '>abt_cons|Research Systems Consulting', $
  628.       '0\IDL Information', '>abt_idl|IDL', $
  629.       '0\ENVI Information', '>abt_envi|ENVI', $
  630.       '2\Visible Human CD Information', '>abt_vh|Visible Human CD']
  631. end                             ;getmenudescription
  632.  
  633.  
  634. Function XFindFont, FontNames
  635. ; See if a font can be found. FontNames = an array of font names.  On exit
  636. ; the function value is either the first found font, or the null string.
  637.  
  638. for i=0, n_elements(FontNames)-1 do begin ;Search for a font
  639.     Device, Font=FontNames(i), Get_Fontnum=fontnum, GET_FONTNAME=s
  640.     if fontnum gt 0 then return, s(0)
  641. endfor
  642. return, ''                      ;Couldn't find the font.
  643. end
  644.  
  645. ;----------------------------------------------------------------------------
  646. ;
  647. ;  Purpose:  Create the push down buttons.
  648. ;
  649. pro createButtons, $
  650.     mainWinBase, $   ; IN: Main window base ID
  651.     buttons          ; IN: buttons created bu buttonDef routine.
  652.  
  653. case !VERSION.OS_FAMILY of
  654.     'Windows' : button_font = 'MS Sans Serif*8'
  655.     'MacOS' : button_font = ''
  656.     ELSE: $                     ;  Find a font for Unix and VMS
  657.         button_font = XFindFont(['-adobe-helvetica-medium-r-normal--10-*-*-*', $
  658.                                  '-misc-fixed-medium-r-normal--10-*-*-*'])
  659. ENDCASE
  660.  
  661. for i=0, N_ELEMENTS(buttons)-1 do begin
  662.  
  663.     buttons[i].btnbase = WIDGET_BASE(mainWinBase, MAP=0, $
  664.                                      xoffset = buttons[i].xoffset, $
  665.                                      yoffset = buttons[i].yoffset)
  666.  
  667.     buttonId = WIDGET_BUTTON(buttons[i].btnbase, $
  668.                              VALUE=buttons[i].value, $
  669.                              UVALUE=buttons[i].uvalue, $
  670.                              XSIZE=buttons[i].xsize, $
  671.                              YSIZE=buttons[i].ysize, $
  672.                              FONT=button_font)
  673. endfor
  674. end
  675.  
  676. ;----------------------------------------------------------------------------
  677. ;
  678. ;  Purpose:  read the required image index newScreen, and display it.
  679. ;
  680. pro showScreen, newScreen, state
  681. t0 = systime(1)
  682.  
  683.  
  684. WSET, state.mainDrawID
  685.  
  686. Header = state.gif_hdr
  687. Image = PReadDemoScreen(newScreen, header, colortb, DEBUG=state.debug)
  688. state.gif_hdr = Header          ;Restore gif status
  689. WIDGET_CONTROL, state.imageBase, MAP=0   ;If we rearrange order of
  690.                                 ; operations, this seems unnecessary. 
  691. TVLCT, colortb
  692. TV, *image                      ;show it
  693.  
  694. for i=0, N_ELEMENTS(state.buttons)-1 do $ ;Map buttons for this screen
  695.   WIDGET_CONTROL, state.buttons[i].btnBase, $
  696.     MAP= state.buttons[i].screenNum eq newScreen
  697.  
  698. state.prevScreenNum = state.curScreenNum
  699. state.curScreenNum  = newScreen
  700. WIDGET_CONTROL, state.imageBase, MAP=1
  701.  
  702. if state.debug then timer, 'ShowScreen ', t0
  703. end
  704.  
  705.  
  706.  
  707.  
  708. ;----------------------------------------------------------------------------
  709. ;
  710. ;  Purpose:  Start the INSIGHT tool.
  711. ;
  712. pro demoStartInsight, top
  713.  
  714.     if (lmgr(/embedded) GT 0) then begin
  715.         result = DIALOG_MESSAGE(/QUESTION, $
  716.            DIALOG_PARENT=top, $
  717.            'Enter a time-limited IDL Insight session ?')
  718.         if (strupcase(result) EQ 'YES') then begin
  719.             tmp=lmgr(/force_demo)
  720.             insight
  721.         endif
  722.     endif else insight
  723. end
  724.  
  725. ;----------------------------------------------------------------------------
  726. ;
  727. ;  Purpose:  This routine is used to start the online
  728. ;            help system. The user value (uval) can come
  729. ;            from either a button or the pulldown menu
  730. ;
  731. pro starthelp, $
  732.     uval,      $ ; IN: user value
  733.     top          ; IN: top level base
  734.  
  735.     result = DIALOG_MESSAGE(/QUESTION, $
  736.         DIALOG_PARENT=top, $
  737.         ['This choice will start the Online Help system.', $
  738.          '', $
  739.          'Do you want to continue ?'])
  740.     if (strupcase(result) EQ 'NO') then RETURN
  741.  
  742.     case uval of
  743.         'DEVENV': begin
  744.  
  745.             ;  Start the online help and display the page
  746.             ;  with the index for the IDL Development Environment
  747.             ;  for the applicable platform.
  748.             ;
  749.             case !VERSION.OS_FAMILY of
  750.                 'unix':    online_help, 13010, /context
  751.                 'vms':     online_help, 13010, /context
  752.                 'Windows': online_help, 14010, /context
  753.                 'MacOS':   online_help, 15010, /context
  754.             endcase
  755.         end
  756.  
  757.         'OOPROG': online_help, book='oog'
  758.  
  759.         ;  Start online help with the context number
  760.         ;  for "platforms supported".
  761.         ;
  762.         'CROSS': online_help, 00010, /context
  763.  
  764.         ;  Start the online help system with the default screen
  765.         ; 
  766.         'NOARG': online_help
  767.  
  768.     endcase
  769.  
  770. end
  771.  
  772.  
  773. ;----------------------------------------------------------------------------
  774. ;
  775. ;  Purpose:  This routine is used to start all demos.
  776. ;            Name must be the name of the procedure to call.
  777. ;            a button or the pulldown menu
  778. ;
  779. pro startapp, $
  780.               Name, $           ;Name of demo
  781.               state, $          ; IN: state structure
  782.               top, $            ; IN: top level base
  783.               EXTRA = extra     ;Extra keyword parameter structure (optional)
  784.  
  785.     if (WIDGET_INFO(state.apptlb, /VALID)) then begin
  786.         result = DIALOG_MESSAGE('Only one demo may run at a time')
  787.         RETURN
  788.     endif
  789.  
  790.     if state.slow and (total(name eq state.slow_demos) gt 0) then begin
  791.         result = $
  792.           DIALOG_MESSAGE(['This demo utilizes computationally intensive', $
  793.                           'graphics.  Response on this machine may be', $
  794.                           'unacceptably slow.', $
  795.                           'Continue anyway?'], $
  796.                          DIALOG_PARENT=top, $
  797.                          /QUESTION)
  798.                                 ;Only display once
  799.         state.slow_demos(where(state.slow_demos eq name)) = 'XXXX'
  800.         if result eq 'No' then return
  801.     endif                          
  802.  
  803.     WIDGET_CONTROL, /HOURGLASS
  804.     idl_demo_reset
  805.     resolve_routine, Name       ;Be sure its compiled/loaded
  806.     state.demo_name = Name      ;Save name of demo
  807.     WIDGET_CONTROL, state.mainWinBase, map=0 ;Unmap menu
  808.     if state.debug then begin   ;Clean up our memory first, we should
  809.                                 ;have nothing allocated except the
  810.                                 ;pointers for the screen cache.
  811.         ptr_free, state.gif_hdr.cache ;Free our screens
  812.         state.gif_hdr.cache = ptr_new() ;by clearing the cache...
  813.         state.memory = memory() ;Save memory state
  814.     endif
  815.  
  816.     if n_elements(extra) gt 0 then $ ;Call it
  817.       call_procedure, Name, GROUP=top, APPTLB = appTLB, _EXTRA=extra $
  818.     else call_procedure, Name, GROUP=top, APPTLB = appTLB
  819.  
  820.     if state.debug then begin
  821.     endif
  822.     if n_elements(appTLB) then state.appTlb = appTLB $
  823.     else state.appTlb = 0L
  824.  
  825. end
  826.  
  827. ;----------------------------------------------------------------------------
  828. ;
  829. ;  Purpose:  GEt the screen size. Returns failure (0) if the 
  830. ;            screen size is too small, returns 1 (success)
  831. ;            otherwise.
  832. ;
  833. function IDL_DEMO_SIZE, $
  834.     DesiredX, $
  835.     DesiredY, $
  836.     ActualX, $
  837.     ActualY
  838.  
  839.     DEVICE, GET_SCREEN_SIZE=scr_size
  840.     ActualX = scr_size[0]
  841.     ActualY = scr_size[1]
  842.  
  843.     if ((DesiredX LE ActualX) AND (DesiredY LE ActualY)) then RETURN, 1
  844.  
  845.     str_x = Strtrim(String(DesiredX), 2)
  846.     str_y = Strtrim(String(DesiredY), 2)
  847.     junk = DIALOG_MESSAGE(['The screen resolution must be at least', $
  848.         str_x + ' by ' + str_y + ' to run this demo.'])
  849.     RETURN, 0
  850. end
  851.  
  852. ;----------------------------------------------------------------------------
  853. ;
  854. ;  Purpose:  Initilize the main demo. Show the start up
  855. ;            screen.
  856. ;
  857. function DemoInit, $
  858.     fullScrXsize, $   ; IN: X monitor size
  859.     fullScrYsize      ; IN: Y monitor size
  860.  
  861. case !Version.Os_Family OF
  862.     'vms': add = ''
  863.     'Windows': add = '\EXAMPLES\DEMO;'
  864.     'MacOS':   add = ':Examples:Demo,'
  865.     ELSE:      add = '/examples/demo:'
  866. endcase
  867.  
  868. if add ne '' and strpos(!path, add) lt 0 then $ ;Add our path?
  869.   !Path = !Dir + add + !Path
  870.  
  871.     if ((!D.Flags AND (2L^16)) NE (2L^16)) then begin
  872.         Print, ' '
  873.         Print, 'Unable to start the IDL demo.'
  874.         Print, 'The current device does not support widgets.'
  875.         Print, 'See the "SET_PLOT" command for more information.'
  876.         Print, ' '
  877.         RETURN, -1
  878.     endif
  879.  
  880.     ;  Test for the presence of one of the demo save files to determine
  881.     ;  if the demos have been installed.  (The main demo.sav file is
  882.     ;  always installed on some systems.)  If the file is not present,
  883.     ;  exit with a warning.
  884.     openr, Lun, FILEPATH('d_animate.sav', SUBDIR=['examples','demo']), $
  885.       /GET_LUN, ERROR=i
  886.     if (i Lt 0) then begin
  887.         tmp = DIALOG_MESSAGE( /ERROR, [ $
  888.            'This IDL Demo application is missing files which are normally', $
  889.            'installed with the demo option of the installation.', $
  890.            '', $
  891.            'See your installation guide for details on installing the demo.'])
  892.         RETURN, -1
  893.     endif
  894.     Free_Lun, Lun
  895.  
  896.     ;  Initialize the device.
  897.     ;
  898.     if (((!D.Name EQ 'X') OR (!D.NAME EQ 'MacOS')) AND $
  899.         (!D.N_Colors GE 256L)) then DEVICE, Pseudo_Color=8
  900.     DEVICE, Decomposed=0, Bypass_Translation=0
  901.  
  902.     ;  This is needed since the screens are unmapped and then mapped.
  903.     ;
  904.     DEVICE, RETAIN=2
  905.  
  906.     ; Determine the Screen Size
  907.     ;
  908.     if !Version.Os_Family EQ 'MacOS' then begin
  909.        minXsize = 640
  910.        minYsize = 440
  911.     endif else begin
  912.        minXsize = 640
  913.        minYsize = 480
  914.     endelse
  915.     if not(IDL_DEMO_SIZE(minXsize, minYsize, fullScrXsize, fullScrYsize)) $
  916.        then RETURN, -1
  917.  
  918.     ;  Set default font for text in widgets
  919.     ;
  920.     CASE !Version.OS_Family OF
  921.     ;  Don't set it for Windows or Mac, the systems defaults are fine
  922.     'Windows': 
  923.     'MacOS': 
  924.     ELSE:  BEGIN                ;  Find a font for Unix and VMS. 
  925.         save_wind = !D.Window
  926.         Window, /Free, Xsize=4, Ysize=4, /Pixmap, Retain=2
  927.         pix_win = !D.Window
  928.         Font = XFindFont(['-adobe-helvetica-medium-r-normal--14-*-*-*', $
  929.                           '9x15'])
  930.         wdelete, pix_win
  931.         wset, save_wind
  932.         IF (font ne '') THEN Widget_Control, Default_Font= Font
  933.     ENDCASE
  934. ENDCASE
  935.  
  936. RETURN, 1                       ;  Return 1 for success.
  937.  
  938. end
  939.  
  940. ;----------------------------------------------------------------------------
  941. ;
  942. ;  Purpose:  Cleanup procedure.
  943. ;
  944. pro idl_demo_cleanup, $
  945.     tlb     ; IN: Top level base
  946.  
  947.     WIDGET_CONTROL, tlb, GET_UVALUE=state, /NO_COPY
  948.  
  949.     ;  Restore the previous color table.
  950.     ;
  951.     TVLCT, state.colorTable
  952.     free_lun, state.gif_hdr.lun
  953.     ptr_free, state.gif_hdr.cache
  954.     !quiet = state.quiet
  955.     if state.debug then begin
  956.         print, "Looking for heap vars, windows, file units:
  957.         help, /heap
  958.         help, /files
  959.         print, '!d.window: ', !d.window
  960.     end
  961. end   ; idl_demo_cleanup
  962.  
  963.  
  964. ;----------------------------------------------------------------------------
  965. ;
  966. ;  Purpose:  Main event handler.
  967. ;
  968. ; The uvalue (or in the case of pulldown menus, the uvalue is saved in
  969. ; state.MenuActions) is encoded as follows:
  970. ; quit = quit
  971. ; INSIGHT-START = start insight.
  972. ; >FileName|Title  = display the file FileName in the demotext
  973. ;     directory, with the given title.
  974. ; .n = display screen n (n is a series of digits.)
  975. ; .- = display previous screen
  976. ; ?KEY = call STARTHELP with KEY
  977. ; NAME = call startapp with NAME
  978.  
  979.  
  980. pro idl_demo_event, $
  981.     event      ; IN: event structure.
  982.  
  983. ;  Quit the application using the close box.
  984. ;
  985. WIDGET_CONTROL, event.top, GET_UVALUE=state, /NO_COPY, /HOURGLASS
  986.  
  987. if (TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') then begin
  988.    WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY
  989.    WIDGET_CONTROL, event.top, /DESTROY
  990.    RETURN
  991. endif
  992.  
  993. WIDGET_CONTROL,event.id,GET_UVALUE=uval
  994.  
  995. if state.debug and state.memory(0) ne 0L then begin ;Check demo's memory use?
  996.     mem_end = fix(memory()/1000L) ;In K...
  997.     mem_start = fix(state.memory/1000L)
  998.     print, 'Finished demo ', state.demo_name
  999.     print, 'Memory before start: ', mem_start(0), 'K, after: ', $
  1000.       mem_end(0), ', delta: ', mem_end(0) - mem_start(0)
  1001.     print, 'High-water mark: ', mem_start(4)
  1002.     heap_gc, /VERBOSE
  1003.     device, WINDOW_STATE=w      ;Check for open windows
  1004.     if total(w) gt 1 then begin ;Got too many windows open
  1005.         print, 'ERROR: Only one window should be open:', where(w)
  1006.     endif
  1007.     state.memory = 0L
  1008. endif
  1009.  
  1010.  
  1011.     ;  This CATCH branch handles unexpected errors that might
  1012.     ;  arise in the event loop.  Since the state is retrieved
  1013.     ;  with NO_COPY, it is important to put it back into the
  1014.     ;  user value of event.top so that execution can continue
  1015.     ;  if there is an error caught by CATCH.
  1016.     ;
  1017. ErrorStatus = 0
  1018. CATCH, ErrorStatus
  1019. IF (ErrorStatus NE 0) THEN BEGIN
  1020.     CATCH, /CANCEL
  1021.     v = DIALOG_MESSAGE(['Unexpected error in DEMO:', $
  1022.                         '!ERR_STRING = ' + !ERR_STRING, $
  1023.                         '!SYSERROR = ' + STRTRIM(LONG(!SYSERROR), 2), $
  1024.                         '!SYSERR_STRING = ', !SYSERR_STRING, $
  1025.                         ' ', 'Cleaning up...'], $
  1026.                        DIALOG_PARENT=event.top, $
  1027.                        /ERROR)
  1028.     WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY
  1029.     WIDGET_CONTROL, event.top, /MAP
  1030.     RETURN
  1031. ENDIF
  1032.  
  1033. ; if state.debug then begin       ;Debugging
  1034. ;    if total(tag_names(event) eq 'VALUE') ne 0 then v = event.value $
  1035. ;    else v = '<>'
  1036. ;    print, uval, ' ', v
  1037. ; endif
  1038.  
  1039. if uval eq 'MAIN_PULLDOWN' then $ ;Translate menu pulldowns using action array
  1040.   uval = state.MenuActions(event.value)
  1041.  
  1042. char = strmid(uval, 0, 1)       ;What kind of action
  1043. rest = strmid(uval, 1, strlen(uval)-1)
  1044.  
  1045. if char eq '.' then begin       ;Display a screen
  1046.     if uval eq '.-' then showScreen, state.prevScreenNum, state $
  1047.     else showScreen, fix(rest), state
  1048. endif else if char eq '>' then begin ;Display a file
  1049.     parts = str_sep(rest, '|') ;Get file name & title
  1050.     xdisplayfile, filepath(parts[0] + '.txt', $
  1051.                            SUBDIR=['examples','demo','demotext']), $
  1052.       group=group, HEIGHT=35, WIDTH=80, $
  1053.       title= parts[1]
  1054. endif else if char eq '?' then begin
  1055.     starthelp, rest, event.top
  1056. endif else begin                ;Must be a startapp
  1057.     if uval eq 'quit' then begin ;Quit is a special case
  1058.         WIDGET_CONTROL, event.top, SET_UVALUE=state ;Restore our state
  1059.         WIDGET_CONTROL, event.top, /destroy
  1060.         return
  1061.     endif else if uval eq 'INSIGHT-START' then begin
  1062.         demoStartInsight, event.top
  1063.     endif else begin            ;Just call the app
  1064.         case uval of            ;Check for special cases
  1065.             'ROI-SPACE' : startapp, 'D_ROI', state, event.top, EXTRA={ASTRO:1}
  1066.             'FILTER-SIGNAL' : startapp, 'D_FILTER', state, event.top, $
  1067.               EXTRA={FILENAME: 'damp_sn.dat'}
  1068.             'FILTER-ENGR': startapp, 'D_FILTER', state, event.top, $
  1069.               EXTRA={FILENAME: 'damp_sn.dat'}
  1070.             'FILTER-SPACE': startapp, 'D_FILTER', state, event.top, $
  1071.               EXTRA={FILENAME:'galaxy.dat'}
  1072.             else : startapp, uval, state, event.top ;Normal demo
  1073.         endcase
  1074.     endelse
  1075. endelse
  1076.  
  1077. WIDGET_CONTROL, event.top, SET_UVALUE=state, /NO_COPY ;Restore our state
  1078. END   ; idl_demo_event
  1079.  
  1080.  
  1081.  
  1082.  
  1083. pro demo_timer, text, t0
  1084. t1 = systime(1)
  1085. print, text, ' ', t1 - t0
  1086. t0 = t1
  1087. end
  1088.  
  1089. ;----------------------------------------------------------------------------
  1090. ;
  1091. ;  Purpose:  Main procedure for IDL 5.0 demo.
  1092. ;
  1093. pro demo, $
  1094.           debug=debug
  1095.  
  1096. ; This is a list of demos that are slow.  If we judge the machine to
  1097. ; be slow, and we run one of these demos, a message is displayed the
  1098. ; first time the demo is run.
  1099.  
  1100. if !version.os_family NE 'Windows' then begin
  1101. slow_demos = [ 'D_FLYBY', 'D_GLOBE', 'D_HEART', 'D_OBJECT3D', 'D_ORBIT', $
  1102.                'D_SURFVIEW', 'D_TANKLEAK', 'D_TEXTURE', 'D_USCENSUS', $
  1103.                'D_VIBMEMBR', 'D_VOLRENDR']
  1104. endif else begin
  1105. ;;; Don't allow US Census demo if Windows
  1106. slow_demos = [ 'D_FLYBY', 'D_GLOBE', 'D_HEART', 'D_OBJECT3D', 'D_ORBIT', $
  1107.                'D_SURFVIEW', 'D_TANKLEAK', 'D_TEXTURE', $
  1108.                'D_VIBMEMBR', 'D_VOLRENDR']
  1109. endelse
  1110. debug = keyword_set(debug)
  1111. t0 = systime(1)
  1112. tstart = t0
  1113. quietsave = !quiet
  1114. !quiet = 1                      ;Remove obnoxious messages
  1115.  
  1116. if ( xregistered ( "idl_demo" ) NE 0 ) then RETURN
  1117.  
  1118. if (demoInit(fullScrXsize, fullScrYsize) LT 0) then return
  1119. resolve_routine, 'd_animate'    ;Cause it contains multiple files
  1120. if debug then timer, 'demoinit', t0
  1121.  
  1122.                                 ;  Get the current color table. 
  1123.                                 ;  It will be restored when exiting.
  1124.                                 ;
  1125. TVLCT, colorTable, savedG, savedB, /GET
  1126. colorTable=[[colorTable],[savedG],[savedB]]
  1127.  
  1128. If OpenDemoScreens(filepath('screens.gif', $
  1129.                             SUBDIR=['examples','demo','demodata']), $
  1130.                    Header) $
  1131.   lt 0 then return              ;If we cant find screens file, adios.
  1132.  
  1133.                                 ; Read and display the splash screen
  1134. Image = PReadDemoScreen(n_elements(Header.start)-1, $  ;Index of splash screen
  1135.                         Header, Colortb, /NO_CACHE)
  1136. demoSplashStart, fullScrXsize, fullScrYsize, *Image, $ ;  Display splash screen
  1137.   colortb, splashBase, startSplash
  1138. Ptr_Free, Image                 ;No longer required
  1139.  
  1140. if debug then timer, 'demosplashstart', t0
  1141.  
  1142. WIDGET_CONTROL, /HOURGLASS
  1143.  
  1144. ;  Setup the Main Window and Pull Down Menus.
  1145. if ((!version.os_family EQ 'MacOS') AND $
  1146.     (fullScrXsize LT 700 OR fullScrYsize LT 560)) then begin
  1147.  
  1148. ;  Use a scrolling base to allow access to all of demo screen on MacOS
  1149. ;  with small screen
  1150.     xPad = 20
  1151.     yPad = 20
  1152.     mainWinBase = WIDGET_BASE ( TITLE="IDL Demo",  /COLUMN, $
  1153.                                 /ALIGN_CENTER, $
  1154.                                 XSIZE=640, YSIZE=480, $
  1155.                                 X_SCROLL_SIZE=fullScrXsize - xPad, $
  1156.                                 Y_SCROLL_SIZE=fullScrYsize - yPad, $
  1157.                                 MBAR=mainWinMenuBase, TLB_FRAME_ATTR=1, $
  1158.                                 /TLB_KILL_REQUEST_EVENTS, $
  1159.                                 MAP=0 )
  1160. endif else begin
  1161.     mainWinBase = WIDGET_BASE ( TITLE="IDL Demo",  /COLUMN, $
  1162.                                 /ALIGN_CENTER, $
  1163.                                 MBAR=mainWinMenuBase, TLB_FRAME_ATTR=1, $
  1164.                                 /TLB_KILL_REQUEST_EVENTS, $
  1165.                                 MAP=0 )
  1166. endelse
  1167.  
  1168. GetMenuDescription, MenuDescription
  1169.  
  1170. nmenus = n_elements(MenuDescription) /2 ;# of menu items.
  1171. MenuDescription = REFORM(MenuDescription, 2, nmenus, /OVERWRITE)
  1172.  
  1173. mainWinMenu = CW_PDMENU ( mainWinMenuBase, MenuDescription(0,*), $
  1174.                           /RETURN_INDEX, /MBAR, UVALUE='MAIN_PULLDOWN' )
  1175.  
  1176.  
  1177. ;  Create the base for the images and buttons.
  1178. imageBase = WIDGET_BASE(mainWinBase, XSIZE=630, YSIZE=410)
  1179.  
  1180. ;  Create the status message area.
  1181. startMainStatus = "Welcome to the IDL 5.0 Demo: Please select a topic..."
  1182. currMainStatus = startMainStatus
  1183. statusAreaBase = WIDGET_BASE ( mainWinBase, frame=3 )
  1184. statusAreaMsg = WIDGET_LABEL(statusAreaBase, VALUE=startMainStatus, $
  1185.                              /ALIGN_LEFT )
  1186. if debug then timer, 'MainWindowCreate', t0
  1187.  
  1188. ;  Do as much as possible to load the main image before ending splash screen.
  1189.  
  1190. buttonDef, buttons
  1191. if debug then timer, 'ButtonDef', t0
  1192. createButtons, imageBase, buttons
  1193. if debug then timer, 'CreateButtons', t0
  1194. newMainDraw = WIDGET_DRAW(imageBase, XSIZE=630, YSIZE=410)
  1195.  
  1196. WIDGET_CONTROL, mainWinBase, /REALIZE, MAP=0
  1197.  
  1198. WIDGET_CONTROL, newMainDraw, GET_VALUE=mainDrawID
  1199.  
  1200. WSET, mainDrawID
  1201.  
  1202.                                 ;  Take down the splash screen.
  1203.                                 ;
  1204. demoSplashEnd, startSplash, splashBase, debug
  1205. if debug then timer, 'SplashEnd', t0
  1206.  
  1207. mainWinInfo = { $               ;  Create the main state structure.
  1208.                 mainWinBase:mainWinBase, $
  1209.                 imageBase : imageBase, $
  1210.                 buttons: buttons, $
  1211.                 mainDrawID: mainDrawID, $
  1212.                 apptlb : 0L, $
  1213.                 curScreenNum: 0L, $
  1214.                 prevScreenNum: 0L, $
  1215.                 MenuActions : MenuDescription(1,*), $
  1216.                 colorTable: colorTable, $ ; Color table to restore
  1217.                 quiet: quietsave, $
  1218.                 gif_hdr: temporary(header), $
  1219.                 slow : 0, $
  1220.                 demo_name: '<Startup>', $
  1221.                 memory : memory(), $
  1222.                 debug : debug,  $
  1223.                 slow_demos : slow_demos $
  1224.               }
  1225.  
  1226.  
  1227. MenuDescription = 0             ;All done with the menu
  1228.  
  1229. showScreen, 0, mainWinInfo
  1230.  
  1231. WIDGET_CONTROL, mainWinBase, /map
  1232.  
  1233.                                 ;Is this machine slow?  Very approximate...
  1234. mainWinInfo.slow = (systime(1) - tstart ) gt 5
  1235.  
  1236.                                 ; Save state in top base uvalue
  1237. WIDGET_CONTROL, mainWinBase, SET_UVALUE=mainWinInfo, /no_copy
  1238.  
  1239.                                 ; Register program with XManager.
  1240.                                 ;
  1241. if debug then timer, 'Total Time', tstart
  1242.  
  1243. XMANAGER, "idl_demo", mainWinBase, $
  1244.   EVENT_HANDLER="idl_demo_event", $
  1245.   /NO_BLOCK, $
  1246.   CLEANUP="idl_demo_cleanup"
  1247.  
  1248. end                             ; idl_demo
  1249.  
  1250.  
  1251. ; * Main Procedure for embedded mode.
  1252. PRO MAIN
  1253. DEMO
  1254. END
  1255.